Release 10.1A: OpenEdge Data Management:
SQL Reference
CASE
Specifies a series of search conditions and associated result expressions. The general form is called a searched case expression. SQL returns the value specified by the first result expression whose associated search condition evaluates as true. If none of the search conditions evaluates as true, the
CASEexpression returns aNULLvalue, or the value of some other default expression if theCASEexpression includes theELSEclause.
CASEalso supports syntax for a shorthand notation, called a simple case expression, for evaluating whether one expression is equal to a series of other expressions.Syntax
searched_case_expr
simple_case_expr
CASESpecifies a searched case expression. It must be followed by one or more
WHEN-THENclauses, each specifying a search condition and corresponding expression.WHEN search_condition THEN { result_expr | NULL }Specifies a search condition and corresponding expression. SQL evaluates search_condition. If
search_conditionevaluates as true,CASEreturns the value specified by result_expr, orNULL, if the clause specifiesTHEN NULL.If
search_conditionevaluates as false, SQL evaluates the nextWHEN-THENclause, if any, or theELSEclause, if it is specified.CASE primary_exprSpecifies a simple case expression. In a simple case expression, one or more
WHEN-THENclauses specify two expressions.WHEN expr THEN { result_expr | NULL }Prompts SQL to evaluate
exprand compare it withprimary_exprspecified in theCASEclause. If they are equal,CASEreturns the value specified byresult_expr(orNULL, if the clause specifiesTHEN NULL).If
expris not equal toprimary_expr, SQL evaluates the nextWHEN-THENclause, if any, or theELSEclause, if it is specified.ELSE { expr | NULL }Specifies an optional expression whose value SQL returns if none of the conditions specified in
ExamplesWHEN-THENclauses are satisfied. If theCASEexpression omits theELSEclause, it is the same as specifyingELSE NULL.A simple case expression can always be expressed as a searched case expression. This example illustrates a simple case expression:
The simple case expression in the preceding
CASEexample is equivalent to the following searched case expression:
The following example shows a searched case expression that assigns a label denoting suppliers as 'In Mass' if the state column value is 'MA':
The following example shows the equivalent simple case expression:
Notes
Compatibility
SQL compatible
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |